﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data.SqlClient;
using System.Data;
using System.Data.SqlTypes;

namespace DataAccess.Operate
{
    public class DA_Report_SalesAlone_Operate:SqlInteractionBase
    {
        private DataEntity.T_Report_SalesAlone _objMessage = null;
        public override bool Insert(object obj)
        {
            SqlCommand cmdToExecute = new SqlCommand();
            cmdToExecute.CommandText = "dbo.[sp_t_Report_SalesAlone_Insert]";
            cmdToExecute.CommandType = CommandType.StoredProcedure;

            // Use base class' connection object
            cmdToExecute.Connection = _mainConnection;
            this._objMessage = (DataEntity.T_Report_SalesAlone)obj;
            try
            {
                cmdToExecute.Parameters.Add(new SqlParameter("@guidReport_SalesAlone_ID", SqlDbType.UniqueIdentifier, 16, ParameterDirection.Input, false, 0, 0, "", DataRowVersion.Proposed, _objMessage.Report_SalesAlone_ID));
                cmdToExecute.Parameters.Add(new SqlParameter("@guidReport_SalesAlone_ProjectID", SqlDbType.UniqueIdentifier, 16, ParameterDirection.Input, false, 0, 0, "", DataRowVersion.Proposed, _objMessage.Report_SalesAlone_ProjectID));
                cmdToExecute.Parameters.Add(new SqlParameter("@iReport_SalesAlone_ExchangeTypeID", SqlDbType.Int, 4, ParameterDirection.Input, false, 10, 0, "", DataRowVersion.Proposed, _objMessage.Report_SalesAlone_ExchangeTypeID));
                cmdToExecute.Parameters.Add(new SqlParameter("@iReport_SalesAlone_PropertyTypeID", SqlDbType.Int, 4, ParameterDirection.Input, false, 10, 0, "", DataRowVersion.Proposed, _objMessage.Report_SalesAlone_PropertyTypeID));
                cmdToExecute.Parameters.Add(new SqlParameter("@daReport_SalesAlone_ExchangeDate", SqlDbType.DateTime, 8, ParameterDirection.Input, false, 0, 0, "", DataRowVersion.Proposed, _objMessage.Report_SalesAlone_ExchangeDate));
                cmdToExecute.Parameters.Add(new SqlParameter("@sReport_SalesAlone_ReportNO", SqlDbType.NVarChar, 50, ParameterDirection.Input, false, 0, 0, "", DataRowVersion.Proposed, _objMessage.Report_SalesAlone_ReportNO));
                cmdToExecute.Parameters.Add(new SqlParameter("@sReport_SalesAlone_Subscribe", SqlDbType.NVarChar, 50, ParameterDirection.Input, false, 0, 0, "", DataRowVersion.Proposed, _objMessage.Report_SalesAlone_Subscribe));
                cmdToExecute.Parameters.Add(new SqlParameter("@sReport_SalesAlone_Operator", SqlDbType.NVarChar, 200, ParameterDirection.Input, false, 0, 0, "", DataRowVersion.Proposed, _objMessage.Report_SalesAlone_Operator));
                cmdToExecute.Parameters.Add(new SqlParameter("@sReport_SalesAlone_SellUnit", SqlDbType.NVarChar, 200, ParameterDirection.Input, false, 0, 0, "", DataRowVersion.Proposed, _objMessage.Report_SalesAlone_SellUnit));
                cmdToExecute.Parameters.Add(new SqlParameter("@sReport_SalesAlone_Buyer", SqlDbType.NVarChar, 200, ParameterDirection.Input, false, 0, 0, "", DataRowVersion.Proposed, _objMessage.Report_SalesAlone_Buyer));
                cmdToExecute.Parameters.Add(new SqlParameter("@dcReport_SalesAlone_Area", SqlDbType.Decimal, 9, ParameterDirection.Input, false, 18, 1, "", DataRowVersion.Proposed, _objMessage.Report_SalesAlone_Area));
                cmdToExecute.Parameters.Add(new SqlParameter("@sReport_SalesAlone_Discount", SqlDbType.NVarChar, 50, ParameterDirection.Input, false, 0, 0, "", DataRowVersion.Proposed, _objMessage.Report_SalesAlone_Discount));
                cmdToExecute.Parameters.Add(new SqlParameter("@sReport_SalesAlone_PayType", SqlDbType.NVarChar, 200, ParameterDirection.Input, false, 0, 0, "", DataRowVersion.Proposed, _objMessage.Report_SalesAlone_PayType));
                cmdToExecute.Parameters.Add(new SqlParameter("@dcReport_SalesAlone_Price", SqlDbType.Decimal, 9, ParameterDirection.Input, false, 18, 1, "", DataRowVersion.Proposed, _objMessage.Report_SalesAlone_Price));
                cmdToExecute.Parameters.Add(new SqlParameter("@dcReport_SalesAlone_Margins", SqlDbType.Decimal, 9, ParameterDirection.Input, false, 18, 1, "", DataRowVersion.Proposed, _objMessage.Report_SalesAlone_Margins));
                cmdToExecute.Parameters.Add(new SqlParameter("@dcReport_SalesAlone_AgencyCost", SqlDbType.Decimal, 9, ParameterDirection.Input, false, 18, 1, "", DataRowVersion.Proposed, _objMessage.Report_SalesAlone_AgencyCost));
                cmdToExecute.Parameters.Add(new SqlParameter("@dcReport_SalesAlone_CancelComm", SqlDbType.Decimal, 9, ParameterDirection.Input, false, 18, 1, "", DataRowVersion.Proposed, _objMessage.Report_SalesAlone_CancelComm));
                cmdToExecute.Parameters.Add(new SqlParameter("@sReport_SalesAlone_Remark", SqlDbType.NVarChar, 1000, ParameterDirection.Input, false, 0, 0, "", DataRowVersion.Proposed, _objMessage.Report_SalesAlone_Remark));
                cmdToExecute.Parameters.Add(new SqlParameter("@sReport_SalesAlone_Variations", SqlDbType.NVarChar, 50, ParameterDirection.Input, false, 0, 0, "", DataRowVersion.Proposed, _objMessage.Report_SalesAlone_Variations));
                cmdToExecute.Parameters.Add(new SqlParameter("@sReport_SalesAlone_IDNumber", SqlDbType.NVarChar, 200, ParameterDirection.Input, false, 0, 0, "", DataRowVersion.Proposed, _objMessage.Report_SalesAlone_IDNumber));
                cmdToExecute.Parameters.Add(new SqlParameter("@sReport_SalesAlone_Tel", SqlDbType.NVarChar, 200, ParameterDirection.Input, false, 0, 0, "", DataRowVersion.Proposed, _objMessage.Report_SalesAlone_Tel));
                cmdToExecute.Parameters.Add(new SqlParameter("@sReport_SalesAlone_CustomerAddress", SqlDbType.NVarChar, 200, ParameterDirection.Input, false, 0, 0, "", DataRowVersion.Proposed, _objMessage.Report_SalesAlone_CustomerAddress));
                cmdToExecute.Parameters.Add(new SqlParameter("@sReport_SalesAlone_PostCode", SqlDbType.NVarChar, 200, ParameterDirection.Input, false, 0, 0, "", DataRowVersion.Proposed, _objMessage.Report_SalesAlone_PostCode));
                cmdToExecute.Parameters.Add(new SqlParameter("@dcReport_SalesAlone_SalesArea", SqlDbType.Decimal, 9, ParameterDirection.Input, false, 18, 1, "", DataRowVersion.Proposed, _objMessage.Report_SalesAlone_SalesArea));
                cmdToExecute.Parameters.Add(new SqlParameter("@dcReport_SalesAlone_OriginalContractPrice", SqlDbType.Decimal, 9, ParameterDirection.Input, false, 18, 1, "", DataRowVersion.Proposed, _objMessage.Report_SalesAlone_OriginalContractPrice));
                cmdToExecute.Parameters.Add(new SqlParameter("@daReport_SalesAlone_BigDate", SqlDbType.DateTime, 8, ParameterDirection.Input, false, 0, 0, "", DataRowVersion.Proposed, _objMessage.Report_SalesAlone_BigDate));
                cmdToExecute.Parameters.Add(new SqlParameter("@dcReport_SalesAlone_BigPrice", SqlDbType.Decimal, 9, ParameterDirection.Input, false, 18, 1, "", DataRowVersion.Proposed, _objMessage.Report_SalesAlone_BigPrice));
                cmdToExecute.Parameters.Add(new SqlParameter("@dcReport_SalesAlone_BigSumPrice", SqlDbType.Decimal, 9, ParameterDirection.Input, false, 18, 1, "", DataRowVersion.Proposed, _objMessage.Report_SalesAlone_BigSumPrice));
                cmdToExecute.Parameters.Add(new SqlParameter("@daReport_SalesAlone_ContractDate", SqlDbType.DateTime, 8, ParameterDirection.Input, false, 0, 0, "", DataRowVersion.Proposed, _objMessage.Report_SalesAlone_ContractDate));
                cmdToExecute.Parameters.Add(new SqlParameter("@dcReport_SalesAlone_ContractArea", SqlDbType.Decimal, 9, ParameterDirection.Input, false, 18, 1, "", DataRowVersion.Proposed, _objMessage.Report_SalesAlone_ContractArea));
                cmdToExecute.Parameters.Add(new SqlParameter("@dcReport_SalesAlone_ContractPrice", SqlDbType.Decimal, 9, ParameterDirection.Input, false, 18, 1, "", DataRowVersion.Proposed, _objMessage.Report_SalesAlone_ContractPrice));
                cmdToExecute.Parameters.Add(new SqlParameter("@dcReport_SalesAlone_ContractSumPrice", SqlDbType.Decimal, 9, ParameterDirection.Input, false, 18, 1, "", DataRowVersion.Proposed, _objMessage.Report_SalesAlone_ContractSumPrice));
                cmdToExecute.Parameters.Add(new SqlParameter("@dcReport_SalesAlone_LoanAmount", SqlDbType.Decimal, 9, ParameterDirection.Input, false, 18, 1, "", DataRowVersion.Proposed, _objMessage.Report_SalesAlone_LoanAmount));
                cmdToExecute.Parameters.Add(new SqlParameter("@daReport_SalesAlone_ContractLoansDate", SqlDbType.DateTime, 8, ParameterDirection.Input, false, 0, 0, "", DataRowVersion.Proposed, _objMessage.Report_SalesAlone_ContractLoansDate));
                cmdToExecute.Parameters.Add(new SqlParameter("@daReport_SalesAlone_LentDate", SqlDbType.DateTime, 8, ParameterDirection.Input, false, 0, 0, "", DataRowVersion.Proposed, _objMessage.Report_SalesAlone_LentDate));
                cmdToExecute.Parameters.Add(new SqlParameter("@dcReport_SalesAlone_LentAmount", SqlDbType.Decimal, 9, ParameterDirection.Input, false, 18, 1, "", DataRowVersion.Proposed, _objMessage.Report_SalesAlone_LentAmount));
                cmdToExecute.Parameters.Add(new SqlParameter("@dcReport_SalesAlone_TotalReceipt", SqlDbType.Decimal, 9, ParameterDirection.Input, false, 18, 1, "", DataRowVersion.Proposed, _objMessage.Report_SalesAlone_TotalReceipt));
                cmdToExecute.Parameters.Add(new SqlParameter("@dcReport_SalesAlone_RestHouse", SqlDbType.Decimal, 9, ParameterDirection.Input, false, 18, 1, "", DataRowVersion.Proposed, _objMessage.Report_SalesAlone_RestHouse));
                cmdToExecute.Parameters.Add(new SqlParameter("@daReport_SalesAlone_GiveHouseDate", SqlDbType.DateTime, 8, ParameterDirection.Input, false, 0, 0, "", DataRowVersion.Proposed, _objMessage.Report_SalesAlone_GiveHouseDate));
                cmdToExecute.Parameters.Add(new SqlParameter("@iReport_Plan_Audit", SqlDbType.Int, 4, ParameterDirection.Input, false, 10, 0, "", DataRowVersion.Proposed, _objMessage.Report_Plan_Audit));

                if (_mainConnectionIsCreatedLocal)
                {
                    // Open connection.
                    _mainConnection.Open();
                }
                else
                {
                    if (_mainConnectionProvider.IsTransactionPending)
                    {
                        cmdToExecute.Transaction = _mainConnectionProvider.CurrentTransaction;
                    }
                }

                // Execute query.
                _rowsAffected = cmdToExecute.ExecuteNonQuery();
                return true;
            }
            catch (Exception ex)
            {
                // some error occured. Bubble it to caller and encapsulate Exception object
                throw new Exception("T_Report_SalesAlone::Insert::Error occured.", ex);
            }
            finally
            {
                if (_mainConnectionIsCreatedLocal)
                {
                    // Close connection.
                    _mainConnection.Close();
                }
                cmdToExecute.Dispose();
            }
        }


        public override bool Update(object obj)
        {
            SqlCommand cmdToExecute = new SqlCommand();
            cmdToExecute.CommandText = "dbo.[sp_t_Report_SalesAlone_Update]";
            cmdToExecute.CommandType = CommandType.StoredProcedure;

            // Use base class' connection object
            cmdToExecute.Connection = _mainConnection;
            this._objMessage = (DataEntity.T_Report_SalesAlone)obj;
            try
            {
                cmdToExecute.Parameters.Add(new SqlParameter("@guidReport_SalesAlone_ID", SqlDbType.UniqueIdentifier, 16, ParameterDirection.Input, false, 0, 0, "", DataRowVersion.Proposed, _objMessage.Report_SalesAlone_ID));
                cmdToExecute.Parameters.Add(new SqlParameter("@iReport_SalesAlone_ExchangeTypeID", SqlDbType.Int, 4, ParameterDirection.Input, false, 10, 0, "", DataRowVersion.Proposed, _objMessage.Report_SalesAlone_ExchangeTypeID));
                cmdToExecute.Parameters.Add(new SqlParameter("@iReport_SalesAlone_PropertyTypeID", SqlDbType.Int, 4, ParameterDirection.Input, false, 10, 0, "", DataRowVersion.Proposed, _objMessage.Report_SalesAlone_PropertyTypeID));
                cmdToExecute.Parameters.Add(new SqlParameter("@daReport_SalesAlone_ExchangeDate", SqlDbType.DateTime, 8, ParameterDirection.Input, false, 0, 0, "", DataRowVersion.Proposed, _objMessage.Report_SalesAlone_ExchangeDate));
                cmdToExecute.Parameters.Add(new SqlParameter("@sReport_SalesAlone_ReportNO", SqlDbType.NVarChar, 50, ParameterDirection.Input, false, 0, 0, "", DataRowVersion.Proposed, _objMessage.Report_SalesAlone_ReportNO));
                cmdToExecute.Parameters.Add(new SqlParameter("@sReport_SalesAlone_Subscribe", SqlDbType.NVarChar, 50, ParameterDirection.Input, false, 0, 0, "", DataRowVersion.Proposed, _objMessage.Report_SalesAlone_Subscribe));
                cmdToExecute.Parameters.Add(new SqlParameter("@sReport_SalesAlone_Operator", SqlDbType.NVarChar, 200, ParameterDirection.Input, false, 0, 0, "", DataRowVersion.Proposed, _objMessage.Report_SalesAlone_Operator));
                cmdToExecute.Parameters.Add(new SqlParameter("@sReport_SalesAlone_SellUnit", SqlDbType.NVarChar, 200, ParameterDirection.Input, false, 0, 0, "", DataRowVersion.Proposed, _objMessage.Report_SalesAlone_SellUnit));
                cmdToExecute.Parameters.Add(new SqlParameter("@sReport_SalesAlone_Buyer", SqlDbType.NVarChar, 200, ParameterDirection.Input, false, 0, 0, "", DataRowVersion.Proposed, _objMessage.Report_SalesAlone_Buyer));
                cmdToExecute.Parameters.Add(new SqlParameter("@dcReport_SalesAlone_Area", SqlDbType.Decimal, 9, ParameterDirection.Input, false, 18, 1, "", DataRowVersion.Proposed, _objMessage.Report_SalesAlone_Area));
                cmdToExecute.Parameters.Add(new SqlParameter("@sReport_SalesAlone_Discount", SqlDbType.NVarChar, 50, ParameterDirection.Input, false, 0, 0, "", DataRowVersion.Proposed, _objMessage.Report_SalesAlone_Discount));
                cmdToExecute.Parameters.Add(new SqlParameter("@sReport_SalesAlone_PayType", SqlDbType.NVarChar, 200, ParameterDirection.Input, false, 0, 0, "", DataRowVersion.Proposed, _objMessage.Report_SalesAlone_PayType));
                cmdToExecute.Parameters.Add(new SqlParameter("@dcReport_SalesAlone_Price", SqlDbType.Decimal, 9, ParameterDirection.Input, false, 18, 1, "", DataRowVersion.Proposed, _objMessage.Report_SalesAlone_Price));
                cmdToExecute.Parameters.Add(new SqlParameter("@dcReport_SalesAlone_Margins", SqlDbType.Decimal, 9, ParameterDirection.Input, false, 18, 1, "", DataRowVersion.Proposed, _objMessage.Report_SalesAlone_Margins));
                cmdToExecute.Parameters.Add(new SqlParameter("@dcReport_SalesAlone_AgencyCost", SqlDbType.Decimal, 9, ParameterDirection.Input, false, 18, 1, "", DataRowVersion.Proposed, _objMessage.Report_SalesAlone_AgencyCost));
                cmdToExecute.Parameters.Add(new SqlParameter("@dcReport_SalesAlone_CancelComm", SqlDbType.Decimal, 9, ParameterDirection.Input, false, 18, 1, "", DataRowVersion.Proposed, _objMessage.Report_SalesAlone_CancelComm));
                cmdToExecute.Parameters.Add(new SqlParameter("@sReport_SalesAlone_Remark", SqlDbType.NVarChar, 1000, ParameterDirection.Input, false, 0, 0, "", DataRowVersion.Proposed, _objMessage.Report_SalesAlone_Remark));
                cmdToExecute.Parameters.Add(new SqlParameter("@sReport_SalesAlone_Variations", SqlDbType.NVarChar, 50, ParameterDirection.Input, false, 0, 0, "", DataRowVersion.Proposed, _objMessage.Report_SalesAlone_Variations));
                cmdToExecute.Parameters.Add(new SqlParameter("@sReport_SalesAlone_IDNumber", SqlDbType.NVarChar, 200, ParameterDirection.Input, false, 0, 0, "", DataRowVersion.Proposed, _objMessage.Report_SalesAlone_IDNumber));
                cmdToExecute.Parameters.Add(new SqlParameter("@sReport_SalesAlone_Tel", SqlDbType.NVarChar, 200, ParameterDirection.Input, false, 0, 0, "", DataRowVersion.Proposed, _objMessage.Report_SalesAlone_Tel));
                cmdToExecute.Parameters.Add(new SqlParameter("@sReport_SalesAlone_CustomerAddress", SqlDbType.NVarChar, 200, ParameterDirection.Input, false, 0, 0, "", DataRowVersion.Proposed, _objMessage.Report_SalesAlone_CustomerAddress));
                cmdToExecute.Parameters.Add(new SqlParameter("@sReport_SalesAlone_PostCode", SqlDbType.NVarChar, 200, ParameterDirection.Input, false, 0, 0, "", DataRowVersion.Proposed, _objMessage.Report_SalesAlone_PostCode));
                cmdToExecute.Parameters.Add(new SqlParameter("@dcReport_SalesAlone_SalesArea", SqlDbType.Decimal, 9, ParameterDirection.Input, false, 18, 1, "", DataRowVersion.Proposed, _objMessage.Report_SalesAlone_SalesArea));
                cmdToExecute.Parameters.Add(new SqlParameter("@dcReport_SalesAlone_OriginalContractPrice", SqlDbType.Decimal, 9, ParameterDirection.Input, false, 18, 1, "", DataRowVersion.Proposed, _objMessage.Report_SalesAlone_OriginalContractPrice));
                cmdToExecute.Parameters.Add(new SqlParameter("@daReport_SalesAlone_BigDate", SqlDbType.DateTime, 8, ParameterDirection.Input, false, 0, 0, "", DataRowVersion.Proposed, _objMessage.Report_SalesAlone_BigDate));
                cmdToExecute.Parameters.Add(new SqlParameter("@dcReport_SalesAlone_BigPrice", SqlDbType.Decimal, 9, ParameterDirection.Input, false, 18, 1, "", DataRowVersion.Proposed, _objMessage.Report_SalesAlone_BigPrice));
                cmdToExecute.Parameters.Add(new SqlParameter("@dcReport_SalesAlone_BigSumPrice", SqlDbType.Decimal, 9, ParameterDirection.Input, false, 18, 1, "", DataRowVersion.Proposed, _objMessage.Report_SalesAlone_BigSumPrice));
                cmdToExecute.Parameters.Add(new SqlParameter("@daReport_SalesAlone_ContractDate", SqlDbType.DateTime, 8, ParameterDirection.Input, false, 0, 0, "", DataRowVersion.Proposed, _objMessage.Report_SalesAlone_ContractDate));
                cmdToExecute.Parameters.Add(new SqlParameter("@dcReport_SalesAlone_ContractArea", SqlDbType.Decimal, 9, ParameterDirection.Input, false, 18, 1, "", DataRowVersion.Proposed, _objMessage.Report_SalesAlone_ContractArea));
                cmdToExecute.Parameters.Add(new SqlParameter("@dcReport_SalesAlone_ContractPrice", SqlDbType.Decimal, 9, ParameterDirection.Input, false, 18, 1, "", DataRowVersion.Proposed, _objMessage.Report_SalesAlone_ContractPrice));
                cmdToExecute.Parameters.Add(new SqlParameter("@dcReport_SalesAlone_ContractSumPrice", SqlDbType.Decimal, 9, ParameterDirection.Input, false, 18, 1, "", DataRowVersion.Proposed, _objMessage.Report_SalesAlone_ContractSumPrice));
                cmdToExecute.Parameters.Add(new SqlParameter("@dcReport_SalesAlone_LoanAmount", SqlDbType.Decimal, 9, ParameterDirection.Input, false, 18, 1, "", DataRowVersion.Proposed, _objMessage.Report_SalesAlone_LoanAmount));
                cmdToExecute.Parameters.Add(new SqlParameter("@daReport_SalesAlone_ContractLoansDate", SqlDbType.DateTime, 8, ParameterDirection.Input, false, 0, 0, "", DataRowVersion.Proposed, _objMessage.Report_SalesAlone_ContractLoansDate));
                cmdToExecute.Parameters.Add(new SqlParameter("@daReport_SalesAlone_LentDate", SqlDbType.DateTime, 8, ParameterDirection.Input, false, 0, 0, "", DataRowVersion.Proposed, _objMessage.Report_SalesAlone_LentDate));
                cmdToExecute.Parameters.Add(new SqlParameter("@dcReport_SalesAlone_LentAmount", SqlDbType.Decimal, 9, ParameterDirection.Input, false, 18, 1, "", DataRowVersion.Proposed, _objMessage.Report_SalesAlone_LentAmount));
                cmdToExecute.Parameters.Add(new SqlParameter("@dcReport_SalesAlone_TotalReceipt", SqlDbType.Decimal, 9, ParameterDirection.Input, false, 18, 1, "", DataRowVersion.Proposed, _objMessage.Report_SalesAlone_TotalReceipt));
                cmdToExecute.Parameters.Add(new SqlParameter("@dcReport_SalesAlone_RestHouse", SqlDbType.Decimal, 9, ParameterDirection.Input, false, 18, 1, "", DataRowVersion.Proposed, _objMessage.Report_SalesAlone_RestHouse));
                cmdToExecute.Parameters.Add(new SqlParameter("@daReport_SalesAlone_GiveHouseDate", SqlDbType.DateTime, 8, ParameterDirection.Input, false, 0, 0, "", DataRowVersion.Proposed, _objMessage.Report_SalesAlone_GiveHouseDate));

                if (_mainConnectionIsCreatedLocal)
                {
                    // Open connection.
                    _mainConnection.Open();
                }
                else
                {
                    if (_mainConnectionProvider.IsTransactionPending)
                    {
                        cmdToExecute.Transaction = _mainConnectionProvider.CurrentTransaction;
                    }
                }

                // Execute query.
                _rowsAffected = cmdToExecute.ExecuteNonQuery();
                return true;
            }
            catch (Exception ex)
            {
                // some error occured. Bubble it to caller and encapsulate Exception object
                throw new Exception("T_Report_SalesAlone::Update::Error occured.", ex);
            }
            finally
            {
                if (_mainConnectionIsCreatedLocal)
                {
                    // Close connection.
                    _mainConnection.Close();
                }
                cmdToExecute.Dispose();
            }
        }


        public override bool Delete(object obj)
        {
            SqlCommand cmdToExecute = new SqlCommand();
            cmdToExecute.CommandText = "dbo.[sp_t_Report_SalesAlone_Delete]";
            cmdToExecute.CommandType = CommandType.StoredProcedure;

            // Use base class' connection object
            cmdToExecute.Connection = _mainConnection;

            try
            {
                cmdToExecute.Parameters.Add(new SqlParameter("@guidReport_SalesAlone_ID", SqlDbType.UniqueIdentifier, 16, ParameterDirection.Input, false, 0, 0, "", DataRowVersion.Proposed, SqlGuid.Parse(obj.ToString())));

                if (_mainConnectionIsCreatedLocal)
                {
                    // Open connection.
                    _mainConnection.Open();
                }
                else
                {
                    if (_mainConnectionProvider.IsTransactionPending)
                    {
                        cmdToExecute.Transaction = _mainConnectionProvider.CurrentTransaction;
                    }
                }

                // Execute query.
                _rowsAffected = cmdToExecute.ExecuteNonQuery();
                return true;
            }
            catch (Exception ex)
            {
                // some error occured. Bubble it to caller and encapsulate Exception object
                throw new Exception("T_Report_SalesAlone::Delete::Error occured.", ex);
            }
            finally
            {
                if (_mainConnectionIsCreatedLocal)
                {
                    // Close connection.
                    _mainConnection.Close();
                }
                cmdToExecute.Dispose();
            }
        }


        public override object SelectOne(object obj)
        {
            SqlCommand cmdToExecute = new SqlCommand();
            cmdToExecute.CommandText = "dbo.[sp_t_Report_SalesAlone_SelectOne]";
            cmdToExecute.CommandType = CommandType.StoredProcedure;
            DataTable toReturn = new DataTable("t_Report_SalesAlone");
            SqlDataAdapter adapter = new SqlDataAdapter(cmdToExecute);

            // Use base class' connection object
            cmdToExecute.Connection = _mainConnection;
            this._objMessage = new DataEntity.T_Report_SalesAlone();
            try
            {
                cmdToExecute.Parameters.Add(new SqlParameter("@guidReport_SalesAlone_ID", SqlDbType.UniqueIdentifier, 16, ParameterDirection.Input, false, 0, 0, "", DataRowVersion.Proposed, SqlGuid.Parse(obj.ToString())));

                if (_mainConnectionIsCreatedLocal)
                {
                    // Open connection.
                    _mainConnection.Open();
                }
                else
                {
                    if (_mainConnectionProvider.IsTransactionPending)
                    {
                        cmdToExecute.Transaction = _mainConnectionProvider.CurrentTransaction;
                    }
                }

                // Execute query.
                adapter.Fill(toReturn);
                if (toReturn.Rows.Count > 0)
                {
                    _objMessage.Report_SalesAlone_ID = (Guid)toReturn.Rows[0]["Report_SalesAlone_ID"];
                    _objMessage.Report_SalesAlone_ProjectID = (Guid)toReturn.Rows[0]["Report_SalesAlone_ProjectID"];
                    _objMessage.Report_SalesAlone_ExchangeTypeID = (Int32)toReturn.Rows[0]["Report_SalesAlone_ExchangeTypeID"];
                    _objMessage.Report_SalesAlone_PropertyTypeID = (Int32)toReturn.Rows[0]["Report_SalesAlone_PropertyTypeID"];
                    _objMessage.Report_SalesAlone_ExchangeDate = toReturn.Rows[0]["Report_SalesAlone_ExchangeDate"] == System.DBNull.Value ? SqlDateTime.Null : (DateTime)toReturn.Rows[0]["Report_SalesAlone_ExchangeDate"];
                    _objMessage.Report_SalesAlone_ReportNO = toReturn.Rows[0]["Report_SalesAlone_ReportNO"] == System.DBNull.Value ? SqlString.Null : (string)toReturn.Rows[0]["Report_SalesAlone_ReportNO"];
                    _objMessage.Report_SalesAlone_Subscribe = toReturn.Rows[0]["Report_SalesAlone_Subscribe"] == System.DBNull.Value ? SqlString.Null : (string)toReturn.Rows[0]["Report_SalesAlone_Subscribe"];
                    _objMessage.Report_SalesAlone_Operator = toReturn.Rows[0]["Report_SalesAlone_Operator"] == System.DBNull.Value ? SqlString.Null : (string)toReturn.Rows[0]["Report_SalesAlone_Operator"];
                    _objMessage.Report_SalesAlone_SellUnit = toReturn.Rows[0]["Report_SalesAlone_SellUnit"] == System.DBNull.Value ? SqlString.Null : (string)toReturn.Rows[0]["Report_SalesAlone_SellUnit"];
                    _objMessage.Report_SalesAlone_Buyer = toReturn.Rows[0]["Report_SalesAlone_Buyer"] == System.DBNull.Value ? SqlString.Null : (string)toReturn.Rows[0]["Report_SalesAlone_Buyer"];
                    _objMessage.Report_SalesAlone_Area = toReturn.Rows[0]["Report_SalesAlone_Area"] == System.DBNull.Value ? SqlDecimal.Null : (Decimal)toReturn.Rows[0]["Report_SalesAlone_Area"];
                    _objMessage.Report_SalesAlone_Discount = toReturn.Rows[0]["Report_SalesAlone_Discount"] == System.DBNull.Value ? SqlString.Null : (string)toReturn.Rows[0]["Report_SalesAlone_Discount"];
                    _objMessage.Report_SalesAlone_PayType = toReturn.Rows[0]["Report_SalesAlone_PayType"] == System.DBNull.Value ? SqlString.Null : (string)toReturn.Rows[0]["Report_SalesAlone_PayType"];
                    _objMessage.Report_SalesAlone_Price = toReturn.Rows[0]["Report_SalesAlone_Price"] == System.DBNull.Value ? SqlDecimal.Null : (Decimal)toReturn.Rows[0]["Report_SalesAlone_Price"];
                    _objMessage.Report_SalesAlone_Margins = toReturn.Rows[0]["Report_SalesAlone_Margins"] == System.DBNull.Value ? SqlDecimal.Null : (Decimal)toReturn.Rows[0]["Report_SalesAlone_Margins"];
                    _objMessage.Report_SalesAlone_AgencyCost = toReturn.Rows[0]["Report_SalesAlone_AgencyCost"] == System.DBNull.Value ? SqlDecimal.Null : (Decimal)toReturn.Rows[0]["Report_SalesAlone_AgencyCost"];
                    _objMessage.Report_SalesAlone_CancelComm = toReturn.Rows[0]["Report_SalesAlone_CancelComm"] == System.DBNull.Value ? SqlDecimal.Null : (Decimal)toReturn.Rows[0]["Report_SalesAlone_CancelComm"];
                    _objMessage.Report_SalesAlone_Remark = toReturn.Rows[0]["Report_SalesAlone_Remark"] == System.DBNull.Value ? SqlString.Null : (string)toReturn.Rows[0]["Report_SalesAlone_Remark"];
                    _objMessage.Report_SalesAlone_Variations = toReturn.Rows[0]["Report_SalesAlone_Variations"] == System.DBNull.Value ? SqlString.Null : (string)toReturn.Rows[0]["Report_SalesAlone_Variations"];
                    _objMessage.Report_SalesAlone_IDNumber = toReturn.Rows[0]["Report_SalesAlone_IDNumber"] == System.DBNull.Value ? SqlString.Null : (string)toReturn.Rows[0]["Report_SalesAlone_IDNumber"];
                    _objMessage.Report_SalesAlone_Tel = toReturn.Rows[0]["Report_SalesAlone_Tel"] == System.DBNull.Value ? SqlString.Null : (string)toReturn.Rows[0]["Report_SalesAlone_Tel"];
                    _objMessage.Report_SalesAlone_CustomerAddress = toReturn.Rows[0]["Report_SalesAlone_CustomerAddress"] == System.DBNull.Value ? SqlString.Null : (string)toReturn.Rows[0]["Report_SalesAlone_CustomerAddress"];
                    _objMessage.Report_SalesAlone_PostCode = toReturn.Rows[0]["Report_SalesAlone_PostCode"] == System.DBNull.Value ? SqlString.Null : (string)toReturn.Rows[0]["Report_SalesAlone_PostCode"];
                    _objMessage.Report_SalesAlone_SalesArea = toReturn.Rows[0]["Report_SalesAlone_SalesArea"] == System.DBNull.Value ? SqlDecimal.Null : (Decimal)toReturn.Rows[0]["Report_SalesAlone_SalesArea"];
                    _objMessage.Report_SalesAlone_OriginalContractPrice = toReturn.Rows[0]["Report_SalesAlone_OriginalContractPrice"] == System.DBNull.Value ? SqlDecimal.Null : (Decimal)toReturn.Rows[0]["Report_SalesAlone_OriginalContractPrice"];
                    _objMessage.Report_SalesAlone_BigDate = toReturn.Rows[0]["Report_SalesAlone_BigDate"] == System.DBNull.Value ? SqlDateTime.Null : (DateTime)toReturn.Rows[0]["Report_SalesAlone_BigDate"];
                    _objMessage.Report_SalesAlone_BigPrice = toReturn.Rows[0]["Report_SalesAlone_BigPrice"] == System.DBNull.Value ? SqlDecimal.Null : (Decimal)toReturn.Rows[0]["Report_SalesAlone_BigPrice"];
                    _objMessage.Report_SalesAlone_BigSumPrice = toReturn.Rows[0]["Report_SalesAlone_BigSumPrice"] == System.DBNull.Value ? SqlDecimal.Null : (Decimal)toReturn.Rows[0]["Report_SalesAlone_BigSumPrice"];
                    _objMessage.Report_SalesAlone_ContractDate = toReturn.Rows[0]["Report_SalesAlone_ContractDate"] == System.DBNull.Value ? SqlDateTime.Null : (DateTime)toReturn.Rows[0]["Report_SalesAlone_ContractDate"];
                    _objMessage.Report_SalesAlone_ContractArea = toReturn.Rows[0]["Report_SalesAlone_ContractArea"] == System.DBNull.Value ? SqlDecimal.Null : (Decimal)toReturn.Rows[0]["Report_SalesAlone_ContractArea"];
                    _objMessage.Report_SalesAlone_ContractPrice = toReturn.Rows[0]["Report_SalesAlone_ContractPrice"] == System.DBNull.Value ? SqlDecimal.Null : (Decimal)toReturn.Rows[0]["Report_SalesAlone_ContractPrice"];
                    _objMessage.Report_SalesAlone_ContractSumPrice = toReturn.Rows[0]["Report_SalesAlone_ContractSumPrice"] == System.DBNull.Value ? SqlDecimal.Null : (Decimal)toReturn.Rows[0]["Report_SalesAlone_ContractSumPrice"];
                    _objMessage.Report_SalesAlone_LoanAmount = toReturn.Rows[0]["Report_SalesAlone_LoanAmount"] == System.DBNull.Value ? SqlDecimal.Null : (Decimal)toReturn.Rows[0]["Report_SalesAlone_LoanAmount"];
                    _objMessage.Report_SalesAlone_ContractLoansDate = toReturn.Rows[0]["Report_SalesAlone_ContractLoansDate"] == System.DBNull.Value ? SqlDateTime.Null : (DateTime)toReturn.Rows[0]["Report_SalesAlone_ContractLoansDate"];
                    _objMessage.Report_SalesAlone_LentDate = toReturn.Rows[0]["Report_SalesAlone_LentDate"] == System.DBNull.Value ? SqlDateTime.Null : (DateTime)toReturn.Rows[0]["Report_SalesAlone_LentDate"];
                    _objMessage.Report_SalesAlone_LentAmount = toReturn.Rows[0]["Report_SalesAlone_LentAmount"] == System.DBNull.Value ? SqlDecimal.Null : (Decimal)toReturn.Rows[0]["Report_SalesAlone_LentAmount"];
                    _objMessage.Report_SalesAlone_TotalReceipt = toReturn.Rows[0]["Report_SalesAlone_TotalReceipt"] == System.DBNull.Value ? SqlDecimal.Null : (Decimal)toReturn.Rows[0]["Report_SalesAlone_TotalReceipt"];
                    _objMessage.Report_SalesAlone_RestHouse = toReturn.Rows[0]["Report_SalesAlone_RestHouse"] == System.DBNull.Value ? SqlDecimal.Null : (Decimal)toReturn.Rows[0]["Report_SalesAlone_RestHouse"];
                    _objMessage.Report_SalesAlone_GiveHouseDate = toReturn.Rows[0]["Report_SalesAlone_GiveHouseDate"] == System.DBNull.Value ? SqlDateTime.Null : (DateTime)toReturn.Rows[0]["Report_SalesAlone_GiveHouseDate"];
                    _objMessage.Report_Plan_Audit = toReturn.Rows[0]["Report_Plan_Audit"] == System.DBNull.Value ? SqlInt32.Null : (Int32)toReturn.Rows[0]["Report_Plan_Audit"];
                }
                return this._objMessage;
            }
            catch (Exception ex)
            {
                // some error occured. Bubble it to caller and encapsulate Exception object
                throw new Exception("T_Report_SalesAlone::SelectOne::Error occured.", ex);
            }
            finally
            {
                if (_mainConnectionIsCreatedLocal)
                {
                    // Close connection.
                    _mainConnection.Close();
                }
                cmdToExecute.Dispose();
                adapter.Dispose();
            }
        }

    }
}
